﻿namespace Example
{
    using System;
    using System.Net;
    using System.Net.Sockets;
    using Xunit;

    public class DnsFacts
    {
        [Fact]
        public void op_GetHostEntry_IPAddressLoopback()
        {
            var entry = Dns.GetHostEntry(IPAddress.Loopback); // 127.0.0.1

            Assert.NotEqual(1, entry.AddressList.Length);

            Assert.Equal(Environment.MachineName, entry.HostName);
        }

        [Fact]
        public void op_GetHostEntry_stringHostName()
        {
#if DEBUG
            var entry = Dns.GetHostEntry("example.com");

            Assert.Equal(1, entry.AddressList.Length);
            Assert.Equal(AddressFamily.InterNetwork, entry.AddressList[0].AddressFamily);
            Assert.False(entry.AddressList[0].IsIPv6LinkLocal);
            Assert.False(entry.AddressList[0].IsIPv6Multicast);
            Assert.False(entry.AddressList[0].IsIPv6SiteLocal);
            Assert.False(entry.AddressList[0].IsIPv6Teredo);
            Assert.Throws<SocketException>(() => entry.AddressList[0].ScopeId);
            Assert.Equal("192.0.32.10", entry.AddressList[0].ToString());

            Assert.Equal(0, entry.Aliases.Length);
            Assert.Equal("example.com", entry.HostName);
#endif
        }

        [Fact]
        public void op_GetHostEntry_stringIPAddress()
        {
#if DEBUG
            var entry = Dns.GetHostEntry("192.0.32.10");

            Assert.Equal(1, entry.AddressList.Length);
            Assert.Equal(AddressFamily.InterNetwork, entry.AddressList[0].AddressFamily);
            Assert.False(entry.AddressList[0].IsIPv6LinkLocal);
            Assert.False(entry.AddressList[0].IsIPv6Multicast);
            Assert.False(entry.AddressList[0].IsIPv6SiteLocal);
            Assert.False(entry.AddressList[0].IsIPv6Teredo);
            Assert.Throws<SocketException>(() => entry.AddressList[0].ScopeId);
            Assert.Equal("192.0.32.10", entry.AddressList[0].ToString());

            Assert.Equal(0, entry.Aliases.Length);
            Assert.Equal("www.example.com", entry.HostName);
#endif
        }
    }
}